package com.example.demo.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import lombok.extern.slf4j.Slf4j;
@Slf4j
public class TimeCSInvocationHandler implements InvocationHandler{

	private Object target;
	
	public TimeCSInvocationHandler(Object target) {
		this.target=target;
	}
	
	@Override
	public Object invoke(
			Object proxy,
			Method method,
			Object[] args) throws Throwable {
		Long stime = System.currentTimeMillis();
		Object ret = method.invoke(target, args);
		Long useTime = System.currentTimeMillis()-stime;
		log.info("记录方法执行时间,类名：{},方法名：{},耗时：{}",
				this.target.getClass(),
				method.getName(),
				(useTime/1000)
				);
		
		return ret;
	}

}
